import { useNavigate, useLocation } from "react-router-dom";
import { Outlet } from 'react-router-dom'
import { useEffect, useState } from 'react'
const RouterBeforeEach = () => {
    const navigate = useNavigate()
    const location = useLocation()
    const [auth, setAuth] = useState(false)
    useEffect(() => {
        let obj = location.pathname
        let blLogin = localStorage.getItem('login')
        if (obj == '/login' || !blLogin) {
            setAuth(true)
            navigate('/login')
        } else {
            setAuth(false)
        }
    }, [])
    return auth ? <Outlet /> : null
}

export default RouterBeforeEach